import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Put,
  UseGuards,
} from '@nestjs/common';
import { EmployeeService } from './employee.service';
import { CreateEmployeeDto } from './dto/create-employee.dto';
import { UpdateEmployeeDto } from './dto/update-employee.dto';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { QueryPageDto } from '../../common/dto/query.page.dto';
import { QueryEmployeeDto } from './dto/query-employee.dto';
import { AuthGuard } from '@nestjs/passport';
import { Prisma } from '@prisma/client';

@ApiTags('员工管理')
@Controller('employee')
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
export class EmployeeController {
  constructor(private readonly employeeService: EmployeeService) {}

  @Post()
  create(@Body() createEmployeeDto: CreateEmployeeDto) {
    return this.employeeService.create(createEmployeeDto);
  }

  @Post('page')
  findByPage(@Body() query: QueryPageDto<QueryEmployeeDto>) {
    const where: Prisma.EmployeeWhereInput = {
      name: {
        contains: query.model?.name || undefined,
      },
    };
    return this.employeeService.findByPage(query, where);
  }

  @Get()
  findAll() {
    return this.employeeService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.employeeService.findOne(id);
  }

  @Put(':id')
  update(
    @Param('id') id: string,
    @Body() updateEmployeeDto: UpdateEmployeeDto,
  ) {
    return this.employeeService.update(id, updateEmployeeDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.employeeService.remove(id);
  }
}
